package algorithm.easy;

public class Solution69 {

    //输入：x = 8
    //输出：2
    //解释：8 的算术平方根是 2.82842..., 由于返回类型是整数，小数部分将被舍去。
    public static int mySqrt(int x) {
        int low = 0;int high = x;
        int ps;
        for(int i=low;i<high;i++){
            ps=(low+high)/2;
            if(ps*ps >x){
                high = ps;
            }else if(ps*ps<=x){
                low = ps;
            }
        }
        return low;
    }

    public static void main(String[] args){
        int x = 36;
        System.out.println(mySqrt(x));
    }
}
